﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using HMIS.MVC.CommonSupport;
using System.ComponentModel;
using HMIS.Infrastructure.Core.Authority;
using System.Web.Security;
using HMIS.MVC.ViewModel;
using HMIS.FrameWork;

namespace HMIS.MVC.Controllers
{
    public partial class MainController : BaseController
    {
        [ViewPage]
        public ActionResult Login()
        {
            return View();
        }

        [ExtResult]
        [Description("用户登录")]
        public ActionResult UserLogin()
        {
            string loginName = Request["loginname"];
            string pwd = HospUser.GetPwdMD5(Request["pwd"]);
            if (!AuthorityFacade.Validate(loginName, pwd))
                throw new ValidationException("用户名密码错误，或用户状态不可用");

            FormsAuthentication.SetAuthCookie(loginName, true);//加入from验证票据
            Cache.RemoveSessionCache("currentuser");//清空当前用户信息缓存

            return this.JsonFormat(new ExtResult { success = true, id = loginName });
        }
    }
}
